package com.icatw.club.controller;

import com.icatw.club.domain.ClubCollege;
import com.icatw.club.service.IClubCollegeService;
import com.icatw.common.annotation.Log;
import com.icatw.common.core.controller.BaseController;
import com.icatw.common.core.domain.AjaxResult;
import com.icatw.common.core.page.TableDataInfo;
import com.icatw.common.enums.BusinessType;
import com.icatw.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 二级学院Controller
 *
 * @author icatw
 * @date 2022-06-09
 */
@RestController
@RequestMapping("/club/college")
@Api("二级学院模块")
public class ClubCollegeController extends BaseController {
    @Autowired
    private IClubCollegeService clubCollegeService;

    /**
     * 查询二级学院列表
     */
    @PreAuthorize("@ss.hasPermi('club:college:list')")
    @GetMapping("/list")
    @ApiOperation("查询二级学院列表")
    public TableDataInfo list(ClubCollege clubCollege) {
        startPage();
        List<ClubCollege> list = clubCollegeService.selectClubCollegeList(clubCollege);
        return getDataTable(list);
    }

    /**
     * 导出二级学院列表
     */
    @PreAuthorize("@ss.hasPermi('club:college:export')")
    @Log(title = "二级学院" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClubCollege clubCollege) {
        List<ClubCollege> list = clubCollegeService.selectClubCollegeList(clubCollege);
        ExcelUtil<ClubCollege> util = new ExcelUtil<ClubCollege>(ClubCollege.class);
        util.exportExcel(response, list, "二级学院数据");
    }

    /**
     * 获取二级学院详细信息
     */
    @PreAuthorize("@ss.hasPermi('club:college:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId) {
        return AjaxResult.success(clubCollegeService.selectClubCollegeByCId(cId));
    }

    /**
     * 新增二级学院
     */
    @PreAuthorize("@ss.hasPermi('club:college:add')")
    @Log(title = "二级学院" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClubCollege clubCollege) {
        return toAjax(clubCollegeService.insertClubCollege(clubCollege));
    }

    /**
     * 修改二级学院
     */
    @PreAuthorize("@ss.hasPermi('club:college:edit')")
    @Log(title = "二级学院" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClubCollege clubCollege) {
        return toAjax(clubCollegeService.updateClubCollege(clubCollege));
    }

    /**
     * 删除二级学院
     */
    @PreAuthorize("@ss.hasPermi('club:college:remove')")
    @Log(title = "二级学院" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds) {
        return toAjax(clubCollegeService.deleteClubCollegeByCIds(cIds));
    }
}
